<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="社交账号id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户社交账号id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="社交账号名称" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户社交账号名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="用户电话" prop="userPhone">
        <el-input
          v-model="queryParams.userPhone"
          placeholder="请输入用户电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['combat:userzh:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['combat:userzh:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['combat:userzh:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['combat:userzh:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userzhList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="社交账号id" align="center" prop="userId" />
      <el-table-column label="社交账号名称" align="center" prop="userName" />
      <el-table-column label="社交账号昵称" align="center" prop="userNickname" />
      <el-table-column label="用户IP属地" align="center" prop="userIp" />
      <el-table-column label="用户关注量" align="center" prop="userFocusNum" />
      <el-table-column label="用户粉丝量" align="center" prop="userFansNum" />
      <!-- <el-table-column label="家庭住址" align="center" prop="userHomeAddr" /> -->
      <el-table-column label="用户平台" align="center" prop="userPlate" />
      <!-- <el-table-column label="用户类型" align="center" prop="userType" /> -->
      <el-table-column label="用户电话" align="center" prop="userPhone" />
      <el-table-column label="用户简介" align="center" prop="summary" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column width="280px" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
            v-hasPermi="['combat:userzh:detail']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCaiji(scope.row)"
            v-hasPermi="['combat:userzh:detail']"
          >采集</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['combat:userzh:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['combat:userzh:remove']"
          >删除</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleAuth(scope.row)"
            v-hasPermi="['combat:userzh:remove']"
          >授权</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改知乎用户信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="750px" append-to-body>
      <el-form
        inline
        ref="form"
        :model="form"
        :rules="rules"
        label-width="100px"
      >
        <el-form-item label="社交账号ID" prop="userId">
          <el-input
            size="small"
            v-model="form.userId"
            placeholder="请输入用户社交账号id"
          />
        </el-form-item>
        <el-form-item label="社交账号名称" prop="userName">
          <el-input
            size="small"
            v-model="form.userName"
            placeholder="请输入用户社交账号名称"
          />
        </el-form-item>
        <el-form-item label="社交账号昵称" prop="userNickname">
          <el-input
            size="small"
            v-model="form.userNickname"
            placeholder="请输入用户社交账号昵称"
          />
        </el-form-item>
        <el-form-item label="IP属地" prop="userIp">
          <el-input
            size="small"
            v-model="form.userIp"
            placeholder="请输入用户IP属地"
          />
        </el-form-item>
        <el-form-item label="关注量" prop="userFocusNum">
          <el-input
            size="small"
            v-model="form.userFocusNum"
            placeholder="请输入用户关注量"
          />
        </el-form-item>
        <el-form-item label="粉丝量" prop="userFansNum">
          <el-input
            size="small"
            v-model="form.userFansNum"
            placeholder="请输入用户粉丝量"
          />
        </el-form-item>
        <el-form-item label="家庭住址" prop="userHomeAddr">
          <el-input
            size="small"
            v-model="form.userHomeAddr"
            placeholder="请输入家庭住址"
          />
        </el-form-item>
        <el-form-item label="用户平台" prop="userPlate">
          <el-input
            size="small"
            v-model="form.userPlate"
            placeholder="请输入用户平台"
          />
        </el-form-item>
        <el-form-item label="用户电话" prop="userPhone">
          <el-input
            size="small"
            v-model="form.userPhone"
            placeholder="请输入用户电话"
          />
        </el-form-item>
        <el-form-item label="用户简介" prop="summary">
          <el-input
            size="small"
            v-model="form.summary"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
            size="small"
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button class="inBtn" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listUserzh, getUserzh, delUserzh, addUserzh, updateUserzh, caijiUserzh, caijiAllUserzh } from "@/api/combat/userzh";

export default {
  name: "Userzh",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 知乎用户信息表格数据
      userzhList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        userName: null,
        userNickname: null,
        userIp: null,
        userFocusNum: null,
        userFansNum: null,
        userHomeAddr: null,
        userPlate: null,
        userType: null,
        userPhone: null,
        summary: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        rules: {
        //电话必填
        userPhone: [
          { required: true, message: "用户电话不能为空", trigger: "change" }
        ],
      }
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询知乎用户信息列表 */
    getList() {
      this.loading = true;
      listUserzh(this.queryParams).then(response => {
        this.userzhList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        userName: null,
        userNickname: null,
        userIp: null,
        userFocusNum: null,
        userFansNum: null,
        userHomeAddr: null,
        userPlate: null,
        userType: null,
        userPhone: null,
        summary: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加知乎用户信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getUserzh(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改知乎用户信息";
      });
    },
    // 采集按钮操作
    handleCaiji(row) {
      const id = row.id 
      caijiUserzh(id).then(response => {
        if(response.code == 200){
          this.$modal.msgSuccess("采集成功");
          this.getList();
        }
      });
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      //路由跳转
      this.$router.push({
      path: '/userManagement/zhihuD',
      query: {
        id: row.id,
        userId:row.userId
      }
    });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateUserzh(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUserzh(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /**授权 */
    handleAuth(){},
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除知乎用户信息编号为"' + ids + '"的数据项？').then(function() {
        return delUserzh(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('combat/userzh/export', {
        ...this.queryParams
      }, `userzh_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.inBtn {
  color: white;
  width: 106px;
  background: linear-gradient(270deg, #2dbffd 0%, #0e5fff 100%);
  border-radius: 4px 4px 4px 4px;
}

::v-deep .el-pager li.active {
  background: linear-gradient(270deg, #2dbffd 0%, #0e5fff 100%) !important;
}
</style>
